
#ifndef __CLIENT_MAIN_HPP__
#define __CLIENT_MAIN_HPP__

#include "Common.hpp"

// =========================================================
// [T4] - Tic Tac Toe TCP - Client
// =========================================================

// Game Related Initialization.
bool InitGame(void);

// Free Game Resources.
void EndGame(void);

// Try To Connect To The Server.
bool Connect(void);

// Close Network Connection.
void CloseConnection(void);

// OpenGL Initialization Code.
void InitOpenGL(void);

// Free All Resources And Kill The Application. Only Called By The 'atexit()' Function.
void Terminate(void);

// Render One Frame To The game Window. Called By 'glutMainLoop()'.
void DisplayCallback(void);

// Compute The Points For The Score Line Over The Winner Pieces.
void MakeScoreLine(struct Line & line);

// Reshape The Window. Blocks User Reshape.
void ReshapeWindow(int w, int h);

// Save The Mouse X And Y Pos. Only Called By Glut.
void MouseMotionCallback(int x, int y);

// Checks Mouse Button Click. Only Called By Glut.
void MouseCallback(int button, int state, int x, int y);

// Update Keyboard. Only Called By Glut.
void KeyboardCallback(unsigned char key, int x, int y);

// The Only Purpouse Of This Thread Is To Update The Game Data In Real Time,
// Avoiding The Screen To Freeze If The Server Takes To Long To Reply.
class ComunicationsThread {

public:

	ComunicationsThread(void);
	static void threadProc(void * param);
	void begin();
	~ComunicationsThread(void);

private:

	// Private mutex lock.
	Mutex _mtx;

	// Signals to the player thread to terminate.
	char _terminate_thread_flag;

	Thread * _t;
};

#endif // __CLIENT_MAIN_HPP__
